import { uploadType } from '@/utils/util'
import { itemData } from '@/views/oneStopOffice/ElderlyAbilitAssessRecord/questionBankItem/config'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '规则名称',
			prop: 'ruleName',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 12,
			rules: [{ required: true, message: '请输入规则名称' }],
		},
		{
			label: '规则状态',
			prop: 'ruleStatus',
			type: 'radio',
			dicData: [
				{
					label: '启用',
					value: 1,
				},
				{
					label: '停用',
					value: 0,
				},
			],
			span: 12,
			rules: [{ required: true, message: '请选择规则状态' }],
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '选择比对规则内容',
			span: 24,
		},
		{
			label: '选择比对业务（支持多选）',
			prop: 'compareProjects',
			type: 'remoteSelect',
			code: 'BELONG_PROJECT',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 24,
			rules: [{ required: true, message: '请选择比对业务（支持多选）' }],
		},
		{
			label: '选择地区',
			prop: 'compareArea',
			type: 'input',
			span: 24,
		},
		{
			label: '比对数据范围',
			prop: 'compareBetweenTime',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
			rules: [{ required: true, message: '请选择比对数据范围' }],
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '选择比对内容(常识比对和跨区比对不能同时选择)',
			span: 24,
		},
		{
			label: '',
			prop: 'compareOptions',
			type: 'remoteSelect',
			code: 'REPOS_COMPARE_RULE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '规则名称',
			prop: 'ruleName',
			type: 'input',
			span: 8,
		},
		{
			label: '规则状态',
			prop: 'ruleStatus',
			type: 'select',
			dicData: [
				{
					label: '启用',
					value: 1,
				},
				{
					label: '停用',
					value: 0,
				},
			],
			span: 8,
		},
		{
			label: '创建人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '规则名称', prop: 'ruleName' },
		{
			label: '规则状态',
			prop: 'ruleStatus',
			custome: 'tag',
			dicData: [
				{
					label: '启用',
					value: 1,
				},
				{
					label: '停用',
					value: 0,
				},
			],
		},
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omCompareRule_page',
	add: 'view_omCompareRule_add',
	edit: 'view_omCompareRule_edit',
	delete: 'view_omCompareRule_del',
	detail: 'view_omCompareRule_view',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '比对规则设置',
	dictcodes: ['BELONG_PROJECT', 'REPOS_COMPARE_RULE'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'ruleName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '比对详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],

	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			if (form.compareBetweenTime) {
				const tempStr = form.compareBetweenTime.split(',')
				form.compareStartTime = tempStr[0]
				form.compareEndTime = tempStr[1]
			}

			resolve({
				...form,
				compareAreaIds: form.compareArea.toString(),
				compareOptions: form.compareOptions.toString(),
				compareStreetIds: -1,
				compareCommunityIds: -1,
				compareSubprojectIds: -1,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			resolve(query)
		})
	},
	operateFormate: (form) => {
		return new Promise((resolve, reject) => {
			form.compareBetweenTime = [form.compareStartTime, form.compareEndTime].toString()
			form.compareArea = form.compareAreaIds?.split(',')
			form.compareOptions = form.compareOptions?.split(',')
			resolve(form)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
}
